1. /* sffffdiv.cpp by K.Tsuru */
  2. // function ID = 713 DRADIX
  3. /*******************************
  4. SFraction class
  5. It provides the division "x/y".
  6. (x.num/x.den)/(y.num/y.den)=(x.num*y.den)/(x.den*y.num)
  7. ********************************/
  8. #ifndef SN_H
  9. #include "sn.h"
  10. #endif
  11. SFraction FFDiv(const SFraction& x, const SFraction& y){
  12. if(y.Sign(713) == 0) x.num.SetError(x.num.DIVIDED_BY_ZERO,"SF /", 713);
  13. SFraction z; // z.reduceDone = false;
  14. // if(&x == &y) z.SetLong(1, 1); // x/x
  15. if(x == y) z.SetLong(1, 1); // x/x since ver 2.30
  16. else if(x.Sign(713) == 0) z.SetZero();
  17. else {
  18. #if REDUCE_SIZE==0
  19. // z = (xn/xd)/(yn/yd) = (xn*yd)/(xd*yn)
  20. SLong d1 = gcdL(x.num, y.num), d2 = gcdL(x.den, y.den);
  21. z.num = (x.num/d1)*(y.den/d2); z.den = (x.den/d2)*(y.num/d1);
  22. z.reduceDone = true;
  23. #else
  24. if(x.ReduceStepByStep()) {
  25. SLong d1 = gcdL(x.num, y.num), d2 = gcdL(x.den, y.den);
  26. z.num = (x.num/d1)*(y.den/d2); z.den = (x.den/d2)*(y.num/d1);
  27. z.reduceDone = true;
  28. } else {
  29. z.num = x.num*y.den; z.den = x.den*y.num;
  30. z.reduce(false);
  31. }
  32. #endif
  33. }
  34. return z;
  35. }

sffffdiv.cpp : last modifiled at 2017/10/20 10:44:44(1,106 bytes)
created at 2015/12/22 16:07:29
The creation time of this html file is 2017/10/21 15:10:35 (Sat Oct 21 15:10:35 2017).